// index.ts
// 获取应用实例
const app = getApp<IAppOption>()

Component({
  data: {
    motto: '欢迎使用我的ERP管理系统',
    headNavigationTitle: '首页',
    showButtons: [
      {
        name: "新品推荐",
        icon: "success",
        url: ""
      },
      {
        name: "限时特惠",
        icon: "info",
        url: ""
      },
      {
        name: "每日疯抢",
        icon: "warn",
        url: ""
      },
      {
        name: "领优惠卷",
        icon: "waiting",
        url: ""
      }
    ],
    products:[
      {
        name:"这是一件商品，哈哈哈哈，哈哈哈哈，哈哈哈哈",
        image:"https://img.zcool.cn/community/019da060fe89f211013f4720edcaae.jpg@1280w_1l_2o_100sh.jpg",
        price: 199.9
      },
      {
        name:"这是一件商品，哈哈哈哈，哈哈哈哈，哈哈哈哈",
        image:"https://img.zcool.cn/community/0177e5606dc15211013fb11714b291.jpg@1280w_1l_2o_100sh.jpg",
        price: 199.9
      },
      {
        name:"这是一件商品，哈哈哈哈，哈哈哈哈，哈哈哈哈",
        image:"https://img.zcool.cn/community/012a875c130af3a8012092528f19d3.jpg@2o.jpg",
        price: 199.9
      },
      {
        name:"这是一件商品，哈哈哈哈，哈哈哈哈，哈哈哈哈",
        image:"https://img.zcool.cn/community/019da060fe89f211013f4720edcaae.jpg@1280w_1l_2o_100sh.jpg",
        price: 199.9
      },
      {
        name:"这是一件商品，哈哈哈哈，哈哈哈哈，哈哈哈哈",
        image:"https://img.zcool.cn/community/0177e5606dc15211013fb11714b291.jpg@1280w_1l_2o_100sh.jpg",
        price: 199.9
      },
      {
        name:"这是一件商品，哈哈哈哈，哈哈哈哈，哈哈哈哈",
        image:"https://img.zcool.cn/community/012a875c130af3a8012092528f19d3.jpg@2o.jpg",
        price: 199.9
      },
      {
        name:"这是一件商品，哈哈哈哈，哈哈哈哈，哈哈哈哈",
        image:"https://img.zcool.cn/community/019da060fe89f211013f4720edcaae.jpg@1280w_1l_2o_100sh.jpg",
        price: 199.9
      },
      {
        name:"这是一件商品，哈哈哈哈，哈哈哈哈，哈哈哈哈",
        image:"https://img.zcool.cn/community/0177e5606dc15211013fb11714b291.jpg@1280w_1l_2o_100sh.jpg",
        price: 199.9
      }
    ]
  },
  methods: {
    // 事件处理函数
    bindViewTap() {
      wx.navigateTo({
        url: '../logs/logs',
      })
    },
    onChooseAvatar(e: any) {
      const { avatarUrl } = e.detail
      const { nickName } = this.data.userInfo
      this.setData({
        "userInfo.avatarUrl": avatarUrl,
        hasUserInfo: nickName && avatarUrl && avatarUrl !== '',
      })
    },
    onInputChange(e: any) {
      const nickName = e.detail.value
      const { avatarUrl } = this.data.userInfo
      this.setData({
        "userInfo.nickName": nickName,
        hasUserInfo: nickName && avatarUrl && avatarUrl !== '',
      })
    },
    getUserProfile() {
      // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
      wx.getUserProfile({
        desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success: (res) => {
          console.log(res)
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    },
  },
})
